<?php
class ProductAction extends CommonAction {

	public function catalogtree(){
		$this->assign("containList",$this->getCatalogTree());	
		$this->display() ;
	}
	
	
	
	//框架首页
	private function getCatalogTree() {
		//按顺序查询产品类型				
		$model = D ( "product_type" );
		$condition['status'] = 1 ;
		$typeList = $model->where($condition)->order('createdate desc')->select();
		$this->assign("typeList",$typeList);
		//循环取出产品类型		
		$containList ;
		for ($i= 0;$i<count($typeList); $i++){
			$tempList = $typeList[$i];				
			$containList[$i] = $this->getSubFolder(0,$tempList['id'],$i) ;					
		}
		return $containList ;
		//$this->assign("containList",$containList);		
		//$this->display(APP_PATH . '/Tpl/default/ProductCatalog/index.html');
	}
	

	private function getSubFolder($path,$type,$index){
		$str = "" ;		
		$subFolderCondition['childid'] = array('NEQ','0');
		$subFolderCondition['parentid'] = $path ;	
		$subFolderCondition['type_id'] = $type ;
		$subFolderCondition['status'] = 1 ;
		$subFolderList = $this->CommonSimplequery($subFolderCondition,'product_catalog');
		for ($i= 0;$i< count($subFolderList); $i++){		
				$tempList = $subFolderList[$i];
				//dump($tempList) ;						
				if($tempList['parentid'] == 0 ){
					//$str = $str . "<ul class='tree treeFolder treeCheck expand' oncheck='treecheck'>" ;	
					$str = $str . "<ul class='tree treeFolder treeCheck expand' >" ;
				}else{
					$str = $str . "<ul>" ;
				}				
				$str = $str . "<li><a tname='" . $tempList['id'] . "'  tvalue='" . $tempList['name'] .  "' rel='".($index+1) ."'>" . $tempList['name']  . "</a>";
				//遍历子结点				
				$str = $str . $this->getSubFolder($tempList['id'],$type,$index) ;
  				$str = $str . $this->getSubDirect($tempList['id'],$type,$index) ;
				$str = $str . "</li>" ;		
				$str = $str . "</ul>" ;				
		} 		
		return $str;		
	}
	
	private function getSubDirect($path,$type){
		$str = "" ;
		$subDirectCondition['childid'] = '0';
		$subDirectCondition['parentid'] = $path ;
		$subFolderCondition['type_id'] = $type ;
		$subFolderCondition['status'] = 1 ;
		$subDirectList = $this->CommonSimplequery($subDirectCondition,'product_catalog');
		for ($i= 0;$i< count($subDirectList); $i++){
				$tempList = $subDirectList[$i];				
				$str = $str . "<ul>" ;
				$str = $str . "<li><a tname='" . $tempList['id'] . "'  tvalue='" . $tempList['name'] .  "' rel='".($index+1)."'>" . $tempList['name'] . "</a></li>" ;	
				$str = $str . "</ul>" ;
		}
		return $str;		
	}	

}
?>